package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.activity.ActivityGoodDetail;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.utils.ImageUtils;
import nero.yncc.com.createart.utils.TextUtil;

/**
 * Created by nero on 17-6-22.
 */

public class AdapterIndexHotSale extends BaseAdapter {
    Context context;
    ArrayList<GodBean.Goods> arrayList;

    public AdapterIndexHotSale(Context context, ArrayList<GodBean.Goods> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        final GodBean.Goods godBean=arrayList.get(i);

        if(view==null){
            view= LinearLayout.inflate(context, R.layout.adapter_index_hot,null);
            holder=new Holder(view);
            view.setTag(holder);
        }else{
            holder=(Holder)view.getTag();
        }
        holder.tv_content.setText(TextUtil.getText(godBean.getGoods_remark(),"暂无简介"));
        holder.tv_hadsale.setText(TextUtil.getText("已售: "+godBean.getSales_sum(),"已售: 0"));
        holder.tv_money.setText("￥"+godBean.getShop_price());
        holder.tv_title.setText(TextUtil.getText(godBean.getGoods_name(),"暂无名字"));
        ImageUtils.BindImage(context,holder.iv_image,godBean.getOriginal_img(),1);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context,ActivityGoodDetail.class);
                intent.putExtra("id",godBean.getGoods_id());
                context.startActivity(intent);
            }
        });
        return view;
    }

    class Holder{
        public Holder(View root){
            tv_title=root.findViewById(R.id.tv_title);
            tv_content=root.findViewById(R.id.tv_content);
            tv_money=root.findViewById(R.id.tv_money);
            tv_hadsale=root.findViewById(R.id.tv_hadsale);
            iv_image=root.findViewById(R.id.iv_image);
        }
        final TextView tv_title,tv_content,tv_money,tv_hadsale;
        final ImageView iv_image;
    }
}
